﻿	      <?php include("conn.php");
             mysql_query('SET NAMES UTF8'); 

	  

class MyPrizeBean
{
	
	public $images;
	public $shopid;
	public $title;
	public $distance;
	public $evaluate;
	public $reply;
	public $like;
	
	function __construct($images,$shopid,$title,$distance,$evaluate,$reply,$like)
	{
		
		$this->images      = $images;
		$this->shopid      = $shopid;
		$this->title      = $title;
		$this->distance      = $distance;
		$this->evaluate      = $evaluate;
		$this->reply      = $reply;
		$this->like      = $like;
	
	}
}

if($_REQUEST['page']!="")
{
$de=$_REQUEST['page']*$_REQUEST['pagesize'];
$size=$_REQUEST['pagesize'];
}

else
{
$de=0;
$size=5;
}
 if($_REQUEST[state]==2)
{
$desc= "shopid desc";
}

else 
{
$desc= "shopid desc";
}


$cu=1;


$query="select * from shop order by  $desc limit $de,$size";

$rert=mysql_query($query);
	
	$prize = array();
	$zuijin = array();
	$sid = array();
	$dic="";
	$ss="";  
	   function getDistanceBetweenPointsNew($latitude1, $longitude1, $latitude2, $longitude2) {
    $theta = $longitude1 - $longitude2;
    $miles = (sin(deg2rad($latitude1)) * sin(deg2rad($latitude2))) + (cos(deg2rad($latitude1)) * cos(deg2rad($latitude2)) * cos(deg2rad($theta)));
    $miles = acos($miles);
    $miles = rad2deg($miles);
    $miles = $miles * 60 * 1.1515;
    $kilometers = $miles * 1.609344;
    return compact('kilometers'); 

}
	while($rowf=mysql_fetch_array($rert)){
       $ss.=$rowf['shopid'];
     $rert32=mysql_query("select *from user where userid='".$_REQUEST[userid]."'");
     $rowf3=mysql_fetch_array($rert32);
     
       $longitude1=$rowf3['longitude'];$latitude1=$rowf3['latitude'];$longitude2=$rowf['longitude'];$latitude2=$rowf['latitude'];
	 


$distance = getDistanceBetweenPointsNew($latitude1, $longitude1, $latitude2, $longitude2);
foreach ($distance as $unit => $value) {
    $dic= number_format($value,1);
}





  



$counts=mysql_query("select SUM(service) from goodsreply  where   shopid ='".$rowf['shopid']."'");

//评论数
$rss=mysql_fetch_array($counts);
$sum=$rss[0];



$count=mysql_query("select count(*) from goodsreply  where   shopid ='".$rowf['shopid']."'");

//评论数
$rs=mysql_fetch_array($count);
$totalNumber=$rs[0];


$countd=mysql_query("select count(*) from likes  where   shopid ='".$rowf['shopid']."'");

//点赞数
$rsd=mysql_fetch_array($countd);
$totalNumber1=$rsd[0];
if($totalNumber1==0 or $totalNumber1=="")
{
$shu=0;
}
else
{
$shu=$totalNumber1;
}
if($totalNumber!=0)
{
$sum=$totalNumber;
$ping=round(($sum/$totalNumber),2);
}
else
{
$ping=5;

}

if ($ping < 2) {
                            $pinfen = "<span></span><span class='empty'></span><span class='empty'></span><span class='empty'></span><span class='empty'></span>";
                        } 
						
						 else if ($ping < 3 and $ping > 2) {
                            $pinfen = "<span></span><span></span><span class='empty'></span><span class='empty'></span><span class='empty'></span>";
                        } 
						
						 else if ($ping < 4 and $ping > 3) {
                           $pinfen = "<span></span><span></span><span ></span><span class='empty'></span><span class='empty'></span>";
                        }
						 else if ($ping < 5 and $ping > 4) {
                           $pinfen = "<span></span><span></span><span ></span><span></span><span class='empty'></span>";
                        }
						 else  {
                           $pinfen = "<span></span><span></span><span ></span><span ></span><span ></span>";
                        }


	$prize[] = new MyPrizeBean($rowf['images'],$rowf['shopid'],$rowf['name'],$dic,$pinfen,$totalNumber,$shu);
		
	}

echo json_encode($prize);


?>